package com.xzc.domainDriver.exp7.domain;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Data
public class CargoUA {
    private String trackingID;
    private Map<String, RoleV> customerRoles;
    private DeliveryHistoryU deliveryHistoryList;
    private DeliverySpecificationV deliverySpecification;

    public CargoUA(String id) {
        trackingID = id;
        deliveryHistoryList = new DeliveryHistoryU(this);
        customerRoles = new HashMap<>();
    }

    private CargoUA() {
    }

    public CargoUA copyPrototype(String newTrackingID) {
        CargoUA cargoUA = new CargoUA();
        cargoUA.setTrackingID(newTrackingID);
        cargoUA.setCustomerRoles(this.customerRoles);
        cargoUA.setDeliveryHistoryList(this.deliveryHistoryList);
        cargoUA.setDeliverySpecification(this.deliverySpecification);
        return cargoUA;
    }

    public static CargoUA newCargo(CargoUA prototype, String newTrackingID) {
        CargoUA cargoUA = new CargoUA();
        cargoUA.setTrackingID(newTrackingID);
        cargoUA.setCustomerRoles(prototype.customerRoles);
        cargoUA.setDeliveryHistoryList(prototype.deliveryHistoryList);
        cargoUA.setDeliverySpecification(prototype.deliverySpecification);
        return cargoUA;
    }

    public CargoUA newCargo(CargoUA prototype) {
        CargoUA cargoUA = new CargoUA();
        cargoUA.setTrackingID(newTrackingID());
        cargoUA.setCustomerRoles(this.customerRoles);
        cargoUA.setDeliveryHistoryList(prototype.deliveryHistoryList);
        cargoUA.setDeliverySpecification(prototype.deliverySpecification);
        return cargoUA;
    }

    public String newTrackingID() {
        return UUID.randomUUID().toString();
    }
}
